package com.learn.word.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Valley
 * Created by Valley on 2023/6/25 18:40
 */
public class CodeGenerator {

    public static void main(String[] args) {

        String url = "jdbc:mysql://westudy.life:3306/learn_word?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";
        String username = "root";
        String password = "123456";
        String author = "Valley";
        String pattern = "yyyy-MM-dd";
        String dir = System.getProperty("user.dir")+"/src/main/java";
        String parent = "com.generate.test";
        String mapper = System.getProperty("user.dir")+"/src/main/resources/mapper";
        Map<OutputFile, String> map = Collections.singletonMap(OutputFile.xml, mapper);
        List<String> tables = new ArrayList<>();
        tables.add("learn_word_user");
        tables.add("learn_word_word");
        tables.add("learn_word_problem");
        String tablePre = "learn_word_";

        FastAutoGenerator.create(url, username, password)
                .globalConfig(config -> config.author(author).commentDate(pattern).outputDir(dir).disableOpenDir())
                .packageConfig(config -> config.parent(parent).pathInfo(map))
                .strategyConfig(
                        config ->
                            config.addInclude(tables).addTablePrefix(tablePre)

                                    .entityBuilder()
                                    .enableLombok()
                                    .enableFileOverride()
                                    .naming(NamingStrategy.underline_to_camel)
                                    .columnNaming(NamingStrategy.underline_to_camel)

                                    .mapperBuilder()
                                    .enableFileOverride()

                                    .serviceBuilder()
                                    .enableFileOverride()
                                    .formatServiceFileName("I%s")
                                    .formatServiceImplFileName("%sService")

                                    .controllerBuilder()
                                    .enableFileOverride()
                ).execute();

    }

}
